package Longing.lock;

import Longing.demo6;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class text_2 {
    public static void main(String[] args) {
        Connection connection =null;
        PreparedStatement ps =null;
        // 修改，不需要返回结果集
//        ResultSet resultSet = null;
        try {
            connection= demo6.DBUtil.getConnection();
            connection.setAutoCommit(false);
            String sql = "update user set combat_value = combat_value + ? where user_id = 20005; ";
            ps = connection.prepareStatement(sql);
            ps.setInt(1,10000);
            int count = ps.executeUpdate();
            System.out.println(count);
            connection.commit();
        } catch (SQLException throwables) {
            if (connection != null){
                try {
                    connection.rollback();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            throwables.printStackTrace();
        }finally {
            // 修改，不需要返回结果集,传入null
            demo6.DBUtil.close(connection, ps, null);
        }
    }
}
